<template>
	<view class="container">
		<view class="main">
			<view class="sbkk-box" @click="jumpHome"> 随便看看 </view>
			<image src="/static/icon1/01.png" mode="aspectFill"></image>
			<!-- 一键登录 -->
			<view class="yijian-view" v-if="false">
				<view class="phone-number">{{getPhoneCode}}</view>
				<view class="phone-text">
					<image src="../../static/icon1/login-icon.png" mode="widthFix"></image>
					<text>账号安全 放心登录</text>
				</view>
			</view>
			<!-- 手机号登录 -->
			<view class="phone-login">
				<view class="img">
					<image src="/static/icon1/02.png" mode="aspectFill"></image>
					<text>手机</text>
				</view>
				<view class="input">
					<input type="number" maxlength="11" v-model="mobile" placeholder="请输入您的手机号"
						placeholder-class="plaho" />
				</view>
				<view class="img">
					<image src="/static/icon1/03.png" mode="aspectFill"></image>
					<text>验证码</text>
				</view>
				<view class="input">
					<input type="number" maxlength="6" v-model="checkCode" placeholder="请输入您的验证码"
						placeholder-class="plaho" />
					<view v-if="!verificationFlag" style="font-weight: 900;" class="no-send" @click="handleSendCode">
						发送验证码</view>
					<view v-if="verificationFlag" style="color: #a2a2a2;">已发送（{{ count }}S）</view>
				</view>
			</view>
			<!-- 一键登录按钮 -->
			<view class="button" v-if="false"
				style="margin-bottom: 50rpx;border-radius:10rpx;border:none;width: 550rpx;height: 90rpx;font-weight: 600;"
				@click="handleLoginY">本机号码一键登录</view>
			<view v-if="false" class="other-type" @click="changeOther">
				<text style="color: #F39B19;font-weight: 600;font-size: 28rpx;">切换手机号</text>
			</view>
			<!-- 登录按钮 -->
			<view class="login-btn-box">
				<view class="button" @click="handleLogin">登录</view>
				<view class="tip"> 未注册的手机号验证后将自动注册 </view>
			</view>
			<!-- 用户协议 -->
			<view class="user-agreement">
				<view class="article">
					<view class="text">
						<checkbox style="border-radius: 50% !important;" @click="handleSelect()"></checkbox> 您已阅读并同意以下协议
					</view>
					<text style="color: #FCC928" @click="handleOpenArticle(0)">《{{ detailService }}》</text>
					<text style="color: #FCC928" @click="handleOpenArticle(1)">《{{ detailPrivacyT }}》</text>
				</view>
			</view>
			<!-- 第三方登录 ios 去掉 安卓记得开 -->
			<view v-if="system=='android'" class="other-login" style="margin-top: 100rpx;">
				<text style="font-size: 26rpx;">其他登录方式</text>
				<view style="width: 100%;display: flex;justify-content: center;align-items: center;">
					<image style="width:76rpx;margin-right: 40rpx;" src="/static/icon1//sjdl.png" mode="aspectFill"
						@click="changeOther"></image>
					<image src="/static/icon1/13.png" mode="aspectFill" @click="handleWeChatLogin"></image>
					<image v-if="appleOauth" :style="{'margin-left': '40rpx'}" src="/static/icon1/12.png"
						mode="aspectFill" @click="handleAppleLogin"></image>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import unit from '../../libs/newUnit.js'
	import permission from '@/libs/permission.js' //权限插件
	export default {
		data() {
			return {
				isSelect: false, //已选择同意协议
				detailPrivacyT: '隐私政策', //隐私标题
				detailService: '服务协议', //服务
				inviteCode: '', //邀请码
				timer: null, //验证码计时器
				count: 60, //验证码计时时间
				verificationFlag: false, // 是否发送过验证码
				mobile: "", //手机号
				checkCode: "", //验证码		
				loginType: 0, //1 微信 2 苹果
				id: '',
				oldCheckCode: '', //旧的验证码，防止误触登录
				appleOauth: null, // 验证是否支持苹果登录
				isshou: false,
				timerId: 0, //定时器
				isOther: false,
				phoneCode: "",
				system: ''
			}
		},
		computed: {
			getPhoneCode() {
				return this.phoneCode.replace(this.phoneCode.substring(3, 7), '****')
			}
		},
		onLoad(options) {
			// #ifdef APP-PLUS
			if (uni.getStorageSync('region')) {
				this.goToJM()
			} else {
				// this.get_current_location()
			}
			this.system = uni.getSystemInfoSync().platform
			// #endif
			this.getArticleDetailP()
			this.getArticleDetailS()
			// 判断是否是苹果手机
			uni.getProvider({
				service: 'oauth',
				success: res => {
					if (res.provider.indexOf('apple') !== -1) this.appleOauth = true
				}
			})
		},
		onReady() {
			const PhoneL = uni.getStorageSync('loginPhone')
			if (PhoneL) {
				this.mobile = PhoneL
			}
		},
		methods: {
			async query_user_filtering() {
				let res = await this.$fetch(this.$api.query_user_filtering, 'GET')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				if (res.msg) {
					uni.setStorageSync('query_user_filtering', res.data)
				} else {
					uni.removeStorageSync('query_user_filtering')
				}
			},
			async getConfigBanner(e) {
				let tempRegion
				// #ifdef H5
				tempRegion = '330782'
				// #endif
				// #ifdef APP-PLUS
				tempRegion = uni.getStorageSync('region1').slice(0, 6)
				// #endif
				let res = await this.$fetch(this.$api.bannerByToken, {
					region: e ? e : tempRegion
				}, 'GET')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				let newList = []
				for (let i = 0; i < res.data.length; i++) {
					let resdate = res.data[i]
					resdate.img = `https://images.linglinggong.net/${resdate.img}`
					newList.push(resdate)
				}
				uni.setStorageSync('configBanner', newList)
				return
			},
			async requestAndroidPermission(permisionID) {
				uni.showModal({
					title: '提醒',
					content: '获取开放区域需要您的位置，请在权限管理中同意位置信息授权',
					confirmText: '去开启',
					success(res) {
						if (res.confirm) {
							permission.gotoAppPermissionSetting()
						}
					}
				})
			},
			jumpHome() {
				uni.reLaunch({
					url: "/pages/index/index"
				})
			},
			// 点击
			handleSelect() {
				this.isSelect = !this.isSelect
			},
			handleLoginY() {
				if (!this.isSelect) {
					uni.showToast({
						title: '请先阅读并勾选底部协议~',
						icon: 'none'
					})
					uni.pageScrollTo({
						scrollTop: 100,
						duration: 300
					})
					return
				}
			},
			// 一键登录
			loginYi() {
				let that = this;
				// #ifdef APP-PLUS
				let channel = uni.getStorageSync('channel')
				let pinf = plus.push.getClientInfo();
				let cid = pinf.clientid;
				uni.setStorageSync('cid', cid)
				let adcode = uni.getStorageSync('region').slice(0, 6)
				let inviteCode = this.inviteCode
				// #endif
				uni.preLogin({
					provider: 'univerify',
					success() {
						uni.login({
							provider: 'univerify',
							univerifyStyle: {
								"fullScreen": false, // 是否全屏显示，默认值： false
								"backgroundColor": "#ffffff", // 授权页面背景颜色，默认值：#ffffff
								"backgroundImage": "", // 全屏显示的背景图片，默认值："" （仅支持本地图片，只有全屏显示时支持）  
								"icon": {
									"path": "static/logo2.png" // 自定义显示在授权框中的logo，仅支持本地图片 默认显示App logo   
								},
								"closeIcon": {
									"path": "static/icon1/47.png" // 自定义关闭按钮，仅支持本地图片。 HBuilderX3.3.7+版本支持
								},
								"phoneNum": {
									"color": "#202020",
									"fontSize": "20" // 手机号字体大小 默认值：18// 手机号文字颜色 默认值：#202020  
								},
								"slogan": {
									"color": "#BBBBBB" //  slogan 字体颜色 默认值：#BBBBBB  
								},
								"authButton": {
									"normalColor": "#FCC928", // 授权按钮正常状态背景颜色 默认值：#3479f5  
									"highlightColor": "#FCC928", // 授权按钮按下状态背景颜色 默认值：#2861c5（仅ios支持）  
									"disabledColor": "#FCC928", // 授权按钮不可点击时背景颜色 默认值：#73aaf5（仅ios支持）  
									"textColor": "#1A1A1A", // 授权按钮文字颜色 默认值：#ffffff  
									"title": "本机号码一键登录", // 授权按钮文案 默认值：“本机号码一键登录”  
									"borderRadius": "2px" // 授权按钮圆角 默认值："24px" （按钮高度的一半）
								},
								"otherLoginButton": {
									"visible": true, // 是否显示其他登录按钮，默认值：true  
									"normalColor": "", // 其他登录按钮正常状态背景颜色 默认值：透明 
									"highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值：透明 
									"textColor": "#656565", // 其他登录按钮文字颜色 默认值：#656565  
									"title": "其他登录方式", // 其他登录方式按钮文字 默认值：“其他登录方式”  
									"borderColor": "", //边框颜色 默认值：透明（仅iOS支持）  
									"borderRadius": "0px" // 其他登录按钮圆角 默认值："24px" （按钮高度的一半）
								},
								"privacyTerms": {
									"defaultCheckBoxState": false, // 条款勾选框初始状态 默认值： true
									"uncheckedImage": "", // 可选 条款勾选框未选中状态图片（仅支持本地图片 建议尺寸 24x24px）(3.2.0+ 版本支持)   
									"checkedImage": "", // 可选 条款勾选框选中状态图片（仅支持本地图片 建议尺寸24x24px）(3.2.0+ 版本支持)   
									"checkBoxSize": 12, // 可选 条款勾选框大小，仅android支持
									"textColor": "#BBBBBB", // 文字颜色 默认值：#BBBBBB  
									"termsColor": "#5496E3", //  协议文字颜色 默认值： #5496E3  
									"prefix": "我已阅读并同意", // 条款前的文案 默认值：“我已阅读并同意”  
									"suffix": "并使用本机号码登录", // 条款后的文案 默认值：“并使用本机号码登录”  
									"privacyItems": [ // 自定义协议条款，最大支持2个，需要同时设置url和title. 否则不生效  
										{
											"url": "https://zlg-h5.linglinggong.net/serve.html", // 点击跳转的协议详情页面  
											"title": "用户服务协议" // 协议名称  
										}, {
											"url": "https://zlg-h5.linglinggong.net/privace.html", // 点击跳转的协议详情页面  
											"title": "用户隐私政策" // 协议名称  
										}
									]
								},
								"buttons": { // 自定义页面下方按钮仅全屏模式生效（3.1.14+ 版本支持）
									"iconWidth": "45px", // 图标宽度（高度等比例缩放） 默认值：45px
									"list": [{
										"provider": "apple",
										"iconPath": "/static/apple.png" // 图标路径仅支持本地图片
									}, {
										"provider": "weixin",
										"iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
									}]
								}
							},
							success: res => {
								if (res.errMsg == 'login:ok') {
									//执行云函数
									uniCloud.callFunction({
										name: 'yijianLogin',
										data: {
											// 客户端一键登录接口返回的access_token
											access_token: res.authResult['access_token'],
											// 客户端一键登录接口返回的openid
											openid: res.authResult['openid'],
											adcode: adcode,
											cid: cid,
											channel: channel,
											inviteCode: inviteCode
										}
									}).then(res => {
										//关闭弹框事件
										if (res.result['code'] == 0) {
											let tempObj = res.result['data'].data
											uni.setStorageSync('token', tempObj.token)
											uni.showToast({
												title: '登录成功~',
												icon: 'none'
											})
											if (tempObj.str == '1') {
												if (uni.getStorageSync('str') == '') {
													uni.setStorageSync('str', tempObj.str)
												}
											} else if (tempObj.str == '0') {
												uni.removeStorageSync("str")
											}
											uni.removeStorageSync("date")
											that.getUserInfo()
											that.get_current_location()
											uni.setStorageSync('isAppListFlag', true)
											setTimeout(() => {
												uni.closeAuthView();
											}, 1000)
										} else {
											uni.showToast({
												icon: 'none',
												title: '授权失败~'
											});
										}
										//if end
									}).catch(msg => {
										//关闭弹框事件
										uni.closeAuthView();
										console.error(msg);
									});
								} else {
									//关闭弹框事件
									uni.closeAuthView();
								}
							},
							fail: res => {
								uni.closeAuthView()
							}
						});
					},
					fail: res => {
						console.log(res)
					}
				});
			},
			// 获取文章详情
			async getArticleDetailP() {
				let res = await this.$fetch(this.$api.get_article_by_id, {
					id: 4
				}, 'POST')
				this.detailPrivacyT = res.data.articleTitle || '隐私政策'
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			},
			// 获取文章详情
			async getArticleDetailS() {
				let res = await this.$fetch(this.$api.get_article_by_id, {
					id: 3
				}, 'POST')
				this.detailService = res.data.articleTitle || '服务协议'
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			},
			// 点击协议
			handleOpenArticle(flag) {
				if (flag == 0) {
					uni.navigateTo({
						url: '/pages/user-agreement/service-agreement'
					})
				} else if (flag = 1) {
					uni.navigateTo({
						url: '/pages/user-agreement/privacy-agreement'
					})
				}
			},
			// 用户点击了微信登录-> 获取微信授权信息-> 获取不到说明没有授权 -> 授权之后在获取
			handleWeChatLogin() {
				if (!this.isSelect) {
					uni.showToast({
						title: '请先阅读并勾选底部协议~',
						icon: 'none'
					})
					uni.pageScrollTo({
						scrollTop: 100,
						duration: 300
					})
					return
				}
				uni.showLoading({
					title: '登录中...'
				})
				// 获取微信授权信息
				uni.getUserInfo({
					provider: 'weixin',
					success: (loginRes) => {
						// 获取微信授权信息后登录
						this.weChatDirectLogin(loginRes)
					},
					fail: (loginErr) => {
						this.handleWxLoginAccess() // 授权
					}
				})
			},
			// 调微信登录 （原）
			async weChatDirectLogin(loginRes) {
				var pinf = plus.push.getClientInfo();
				var cid = pinf.clientid; //客户端标识 
				uni.setStorageSync('cid', cid)
				console.log('手机cid', uni.getStorageSync('cid'))
				let res = await this.$fetch(this.$api.login_by_id, {
					id: loginRes.userInfo.unionId,
					loginType: 1,
					cid: cid
				}, 'POST')
				uni.hideLoading()
				// 已注册，直接登录
				if (res.code == 0) {
					// 存储token
					uni.setStorageSync('token', res.data.token)
					uni.showToast({
						title: '登录成功~',
						icon: 'none'
					})
					this.getUserInfo()
				} else if (res.msg == '登录失败 请绑定手机号') {
					// 没有注册，先绑定手机号注册
					plus.nativeUI.toast("首次登陆，请先绑定手机号~");
					let register_obj = {
						avatar: loginRes.userInfo.avatarUrl,
						userName: loginRes.userInfo.nickName,
						unionId: loginRes.userInfo.unionId,
						sex: loginRes.userInfo.gender,
					}
					uni.setStorageSync('register_obj', register_obj)
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/bind-mobile/bind-mobile?id=' + loginRes.userInfo.unionId +
								'&loginType=' + 1
						})
					}, 800)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				this.get_current_location()
			},
			// 微信登录授权
			handleWxLoginAccess() {
				uni.login({
					provider: 'weixin',
					success: (accessRes) => {
						this.handleWeChatLogin()
					},
					fail: (err) => {
						uni.showToast({
							title: '您已取消授权',
							icon: 'none'
						})
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			changeOther() {
				this.isOther = true
				// #ifdef APP-PLUS
				this.loginYi()
				// #endif
			},
			// 点击苹果登录时
			handleAppleLogin() {
				uni.login({
					provider: 'apple',
					success: (loginRes) => {
						console.log('苹果', loginRes)
						this.appleLogin(loginRes.authResult.openid)
					},
					fail: function(err) {
						// 登录失败
						uni.showToast({
							title: '您已取消授权',
							icon: 'none'
						})
					}
				});
			},
			// 登录苹果
			async appleLogin(openId) {
				var pinf = plus.push.getClientInfo();
				var cid = pinf.clientid; //客户端标识 
				uni.setStorageSync('cid', cid)
				console.log('手机cid', uni.getStorageSync('cid'))
				let res = await this.$fetch(this.$api.login_by_id, {
					id: openId,
					loginType: 2,
					cid: cid
				}, 'POST')
				if (res.code == 0) {
					// 存储token
					uni.setStorageSync('token', res.data.token)
					uni.showToast({
						title: '登录成功~',
						icon: 'none'
					})
					this.getUserInfo()
				} else if (res.msg == '登录失败 请绑定手机号') {
					// 没有注册，先绑定手机号注册
					plus.nativeUI.toast("首次登陆，请先绑定手机号~")
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/bind-mobile/bind-mobile?id=' + openId + '&loginType=' + 2
						})
					}, 800)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				this.get_current_location()
			},
			// 验证手机号格式是否正确
			checkLoginNameFormat(mobile) {
				let reg = /^[1][3456789][0-9]{9}$/
				if (!reg.test(mobile)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none'
					})
					return false
				}
				return true
			},
			// 发送验证码
			async handleSendCode() {
				if (!this.checkLoginNameFormat(this.mobile)) return
				this.verificationFlag = true
				const mobile = this.$jsencrypt.setEncrypt(this.$api.publicKey, this.mobile);
				let res = await this.$fetch(this.$api.mobile_verification_code, {
					length: 6,
					mobile
				}, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.timer = setInterval(() => {
					if (this.count == 0) {
						clearInterval(this.timer)
						this.verificationFlag = false
						this.count = 60
					} else {
						this.count = --this.count
					}
				}, 1000)
			},
			async toLogin() {
				// #ifdef APP-PLUS
				let adcode = uni.getStorageSync('region').slice(0, 6)
				let channel = uni.getStorageSync('channel') //渠道标识
				let pinf = plus.push.getClientInfo();
				let cid = pinf.clientid; //客户端标识 
				console.log('获取区域adcode' + adcode)
				let res = await this.$fetch(this.$api.login_by_mobile, {
					adcode: this.mobile == '15757751278' ? 330782 : adcode,
					inviteCode: this.inviteCode,
					mobile: this.mobile,
					checkCode: this.checkCode,
					cid: cid,
					channel: channel
				}, 'POST')
				// #endif
				// #ifdef H5
				let adcode = 330782
				let channel = uni.getStorageSync('channel') //渠道标识
				let res = await this.$fetch(this.$api.login_by_mobile, {
					adcode: this.mobile == '15757751278' ? 330782 : adcode,
					inviteCode: this.inviteCode,
					mobile: this.mobile,
					checkCode: this.checkCode,
					channel: channel
				}, 'POST')
				// #endif
				console.log(res.msg)
				if (res.code) return uni.showToast({
					title: res.msg,
					duration: 6000,
					icon: 'none'
				})
				// 存储 user_token
				uni.setStorageSync('token', res.data.token)
				// 记住手机号
				uni.setStorageSync('loginPhone', this.mobile)
				uni.showToast({
					title: '登录成功~',
					icon: 'none'
				})
				if (res.data.str == '1') {
					if (uni.getStorageSync('str') == '') {
						uni.setStorageSync('str', res.data.str)
					}
				} else if (res.data.str == '0') {
					uni.removeStorageSync("str")
				}
				uni.removeStorageSync("date")
				this.getConfigBanner()
				this.query_user_filtering()
				this.getUserInfo()
				this.get_current_location()
				uni.setStorageSync('isAppListFlag', true)
			},
			//手机登录
			async handleLogin() {
				if (!this.isSelect) {
					uni.showToast({
						title: '请先阅读并勾选底部协议~',
						icon: 'none'
					})
					uni.pageScrollTo({
						scrollTop: 100,
						duration: 300
					})
					return
				}
				//防抖
				if (this.timerId) {
					uni.showLoading({
						title: '太快了,稍后再操作吧',
						icon: 'none'
					});
					return
				} //判断定时器是否存在，如果存在直接跳出函数不执行下面代码
				//定时器时间到了的时候清楚定时器并且把赋值的变量清空
				this.timerId = setTimeout(() => {
					clearTimeout(this.timerId);
					uni.hideLoading()
					this.timerId = null;
				}, 5000)
				if (!this.checkCode) return uni.showToast({
					title: '请输入验证码~',
					icon: 'none'
				})
				let channel = uni.getStorageSync('channel') //渠道标识
				console.log('获取区域adcode' + channel)
				// #ifdef H5
				this.toLogin()
				// #endif
				// #ifdef APP-PLUS
				var pinf = plus.push.getClientInfo();
				var cid = pinf.clientid; //客户端标识 
				uni.setStorageSync('cid', cid)
				console.log('手机cid', uni.getStorageSync('cid'))
				let system = uni.getSystemInfoSync().platform
				let adcode = ''
				if (!uni.getStorageSync('region')) {
					// if (system == 'android') {
					// 	if (plus.device.vendor == 'Huawei' || plus.device.vendor == 'HUAWEI' || plus.device.vendor ==
					// 		'huawei') {
					// 		adcode = 330782
					// 	}
					// }
					this.get_current_location2()
				} else {
					adcode = uni.getStorageSync('region').slice(0, 6)
					this.toLogin()
				}
				// #endif
			},
			// 获取当前用户信息
			async getUserInfo() {
				let res = await this.$fetch(this.$api.get_current_user, {}, 'GET')
				console.log('获取当前用户信息', res)
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				if (res.data.payPwdFlag) {
					uni.setStorageSync('isHavePayPassword', true)
				} else {
					uni.setStorageSync('isHavePayPassword', false)
				}
				uni.setStorageSync('userInfo', res.data)
				uni.setStorageSync('userType', res.data.userType)
				uni.setStorageSync('userId', res.data.userId)
				if (res.data.userType == 1) {
					uni.hideTabBar()
				}
				// 注册用户
				if (res.data.userType == '-1') {
					console.log('未注册')
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/select-identity/select-identity'
						})
					}, 600)
					// 登录用户
				} else {
					console.log('已经注册')
					uni.setStorageSync("level", res.data.user.level) //用户等级
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index',
						})
					}, 600)
				}
				uni.$emit('userLogin', {
					online: 1
				})
			},
			checkGps() {
				uni.setStorageSync('checkGpsOne', true)
				let system = uni.getSystemInfoSync(); // 获取系统信息
				if (system.platform == 'android') { // 判断平台
					var context = plus.android.importClass("android.content.Context");
					var locationManager = plus.android.importClass("android.location.LocationManager")
					var main = plus.android.runtimeMainActivity();
					var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
					if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
						uni.showModal({
							title: '提醒',
							content: '请开启定位',
							confirmText: '去开启',
							showCancel: false, // 不显示取消按钮
							success() {
								if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
									var Intent = plus.android.importClass('android.content.Intent');
									var Settings = plus.android.importClass('android.provider.Settings');
									var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
									main.startActivity(intent); // 打开系统设置定位服务页面
								}
							}
						})
					} else {
						console.log('Android定位功能已开启')
						this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
					}
				} else {
					// 苹果
					if (permission.judgeIosPermission("location")) { //判断iOS上是否给予位置权限，有权限返回true，否则返回false
						this.get_current_location()
						console.log('IOS定位功能已开启')
						// return
					} else {
						console.log('IOS定位功能没有开启')
						uni.showModal({
							title: '提醒',
							content: '请在权限管理中同意位置信息授权',
							confirmText: '去开启',
							// showCancel: false, // 不显示取消按钮
							success(res) {
								if (res.confirm) {
									permission.gotoAppPermissionSetting()
								}
							}
						})
					}
				}
			},
			get_current_location2() {
				uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						uni.setStorageSync('location', [res.latitude, res.longitude])
						this.getAdcode2(res.latitude, res.longitude)
					},
					fail: (res) => {
						this.checkGps()
					}
				})
			},
			getAdcode2(lat, lng) {
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
					data: {
						key: '39fcf04d6c9deb64c8436b40445c829e',
						location: lng + ',' + lat
					},
					success: res => {
						let region = res.data.regeocode.addressComponent.towncode.slice(0, 9)
						uni.setStorageSync('region', region)
						this.toLogin()
						if (uni.getStorageSync('token')) {
							this.upd_user(lat, lng, region) //修改	
						}
					}
				})
			},
			// 获取用户当前的经纬度
			get_current_location() {
				uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						uni.setStorageSync('location', [res.latitude, res.longitude])
						this.getAdcode(res.latitude, res.longitude)
					}
				})
			},
			// 由经纬度查询街道的行政代码
			getAdcode(lat, lng) {
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
					data: {
						key: '39fcf04d6c9deb64c8436b40445c829e',
						location: lng + ',' + lat
					},
					success: res => {
						let region = res.data.regeocode.addressComponent.towncode.slice(0, 9)
						uni.setStorageSync('region', region)
						if (uni.getStorageSync('token')) {
							this.upd_user(lat, lng, region) //修改	
						}
					}
				})
			},
			//更新用户位置
			async upd_user(lat, lng, region) {
				//经纬度保留6位小数
				lat = lat.toFixed(6)
				lng = lng.toFixed(6)
				region = region.slice(0, 9)
				console.log('更新用户位置', lat, lng, region)
				let res = await this.$fetch(this.$api.upd_user, {
					lat: lat,
					lng: lng,
					region: region
				}, 'POST')
				console.log('更新用户位置res', res)
			},
			// 初始化极光
			initIM() {
				console.log('初始化极光——登录页')
				//极光聊天室二次封装
				const dcRichAlert = uni.requireNativePlugin('ZWM-BJXMapView')
				console.log(dcRichAlert)
				//极光初始化
				dcRichAlert.JmessageManagerInit({
					appKey: '6d3c21662373e17b01f9b169'
				}, result => { //没有返回值
				})
			},
			goToJM() {
				let v = unit.get_Open_area(uni.getStorageSync('region'))
				if (!v) {
					// console.log('开放', v)
					uni.navigateTo({
						url: '/pages/jiameng/jiameng'
					})
				} else {
					this.loginYi()
				}
			},
		},
		// 返回首页
		onBackPress(options) {
			uni.switchTab({
				url: '/pages/index/index'
			})
			return true
		},
	}
</script>
<style lang="less" scoped>
	page {
		background-color: #FFFFFF;
	}

	.container {
		width: 100%;
		background-color: #FFFFFF;
		padding-top: var(--status-bar-height);
		height: calc(100vh - var(--status-bar-height));
		display: flex;
		justify-content: center;
		height: 100vh;

		&>.main {
			width: 99%;
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;

			.sbkk-box {
				position: absolute;
				right: 0%;
				top: 4%;
				width: 150rpx;
				color: #999;
			}

			.yijian-view {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				padding-top: 20rpx;
				padding-bottom: 60rpx;

				.phone-number {
					font-size: 48rpx;
					font-weight: 600;
					color: #000;
					padding: 20rpx 0;
				}

				.phone-text {
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 32rpx;
						height: 100%;
					}

					font-size: 24rpx;
					color: #999;
				}
			}

			&>.user-agreement {
				display: flex;
				justify-content: center;
				flex-direction: row;

				.article {
					text-align: center;
					width: 750rpx;

					.text {
						display: inline-block;
					}
				}

				&>.icon {
					icon {
						margin-right: 20rpx;
					}
				}
			}

			&>image {
				margin: 80rpx 0;
				width: 242rpx;
				height: 248rpx;
			}

			&>.phone-login {
				margin-bottom: 50rpx;

				&>.img {
					height: 42rpx;
					margin-bottom: 40rpx;
					display: flex;
					align-items: center;

					image {
						margin-right: 30rpx;
						width: 42rpx;
						height: 42rpx;
					}

					text {
						font-weight: bold;
					}
				}

				&>.input {
					width: 590rpx;
					margin-bottom: 40rpx;
					padding-bottom: 20rpx;
					display: flex;
					align-items: center;
					border-bottom: 2rpx solid #F2F2F2;

					input {
						flex: 1;
						height: 40rpx;
						margin-left: 58rpx;
						border-radius: 0.5px;
						font-size: 14px;
						color: #402110;
					}

					.plaho {
						line-height: 40rpx;
						font-size: 14px;
						color: rgba(64, 33, 16, 0.30);
					}

					&>view {
						font-size: 12px;
						color: #F39B19;
					}
				}
			}

			.other-type {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 100%;
				padding-bottom: 50rpx;

				text {
					font-size: 26rpx;
				}
			}

			.login-btn-box {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				min-height: 170rpx;
				flex-direction: column;
				justify-content: center;

				.button {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 520rpx;
					height: 88rpx;
					border-radius: 10rpx;
					background-color: #FCC928;

					&:active {
						opacity: 0.7;
					}
				}

				.tip {
					color: #F39B19;
					margin-top: 15rpx;
					margin-bottom: 40rpx;
				}
			}

			&>.other-login {
				position: relative;
				width: 590rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-bottom: 60rpx;

				&>text {
					height: 40rpx;
					margin-bottom: 30rpx;
					color: rgba(64, 33, 16, 0.50);
				}

				&>view {
					image {
						width: 70rpx;
						height: 70rpx;
					}
				}
			}
		}
	}
</style>